<template>
  <view>
    <view class="input-search">
    	<uni-easyinput prefixIcon="search"  trim="all" v-model="keyword" :styles="styles" :placeholderStyle="placeholderStyle"></uni-easyinput>
    	<button @click="search">搜索</button>
    </view>
	
	<uni-table ref="table" :loading="loading" emptyText="暂无更多数据" filter-type="search">
		<uni-tr v-for="(item, index) in card_arr" :key="index">
			<uni-td width="100%" align="left" class="td-class" >
				<view class="FBillNo-bgcolor">
					<text>动作：{{ item.action }}</text>
					<text>用户：{{ item.username }}</text>
				</view>
				<view>
					<text>路由：{{ item.url }}</text>
				</view>
				<view>
					<text>日期：{{ item.create_date }}</text>
					<text>{{ item.syn_status==0?'未同步':'已同步' }}</text>
				</view>
				<view>
					<text class="font-red">内容：{{ item.result }}</text>
				</view>
			</uni-td>
        </uni-tr>
    </uni-table>
    <view class="uni-pagination-box">
		<uni-pagination show-icon :page-size="pageSize" :current="currentPage"
        :total="total" @change="change" />
	</view>
  </view>
</template>

<script>
// 引入uni-ui组件
import {
  uniPagination,
  uniIcons,
  uniTable,
  uniTr,
  uniTh,
  uniTd,
  uniEasyinput
} from "@dcloudio/uni-ui"
export default {
  data() {
    return {
      card_arr: [],//当前页码的表格数据
      pageSize: 15,// 每页数据量
      currentPage: 1,// 当前页
      total: 0,// 数据总量
      loading: false,
      selectedIndexs:[],//选中
	  
	  placeholderStyle:'font-size:17px;',
	  styles:{
	  	borderColor: '#999'
	  },
	  keyword:'',
	  where:' 1=1 ',
	  user:uni.getStorageSync('user')
    }
  },
  components: {
    uniPagination,
    uniIcons, //uni-ui的icons组件
    uniTable,
    uniTr,
    uniTh,
    uniTd,
	uniEasyinput
  },
  onPullDownRefresh() {
  	this.getlist()
  	uni.stopPullDownRefresh();
  },
  methods: {
	// 搜索
	search() {
		this.currentPage = 1
		this.getlist();
	},
    //获取列表
    getlist() {
		uni.showLoading({mask:true});
		let username = uni.getStorageSync('username')
		if(username=='admin'){
			//查看全部
		}else{
			this.where = " userid = '"+this.user.userid+"'" 
		}
		
		if(this.keyword!=''){
			this.where += "  and (action like '%"+this.keyword+"%' or result like '%"+this.keyword+"%' or username like '%"+this.keyword+"%') "
		}
		
		this.$Db.queryCount('action_log',this.where).then(res => {
			this.total = res[0].num;//获得总页数
			if(!this.total){
				uni.hideLoading()
			}
		})
		this.$Db.queryDataList('action_log',this.currentPage,this.pageSize,this.where,'id','desc').then(res => {
			this.card_arr = res;
			uni.hideLoading();
		})
    },
    change(e) {
      this.currentPage = e.current
      this.getlist()
    },
  },
  onLoad(e) {
	this.getlist()
	this.$Func.setBarTitle('操作日志')
  }
}
</script>
<style lang="less">
</style>